package com.hqyj.springCloudWeb.service;

import com.hqyj.entity.account.Resource;
import com.hqyj.entity.account.Role;
import com.hqyj.entity.account.User;
import com.hqyj.entity.common.ResultEntity;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author yun
 * @date 2021-5-13 18:03
 */
@FeignClient(name = "client-account")//这里的name是被调用的服务器的唯一标识
@Component
@RequestMapping("/api/account")
public interface AccountOpenFeignClient {

    /**
     * 127.0.0.1:8762/api/account/user?userName=admin ---- get
     */
    @GetMapping("/user")
    User selectUserByUserName(@RequestParam String userName);

    /**
     * 127.0.0.1:8762/api/account/roles/1 ---- get
     */
    @GetMapping(value = "/roles/{userId}")
    List<Role> getRolesByUserId(@PathVariable int userId);

    /**
     * 127.0.0.1:8762/api/account/resources/1 ---- get
     */
    @GetMapping(value = "/resources/{roleId}")
    List<Resource> getResourcesByRoleId(@PathVariable int roleId);

    /**
     * 127.0.0.1:8762/api/account/user ---- put
     * {"id":1,"userName":"admin", "password":"123456"}
     */
    @PutMapping(value = "/user", consumes = "application/json")
    ResultEntity<User> updateUserByUser(@RequestBody User user);

    /**
     * 127.0.0.1/api/account/users?userName=admin&email=1111@qq.com ---- get
     */
    @GetMapping("/users")
    List<User> getUserByUserNameOrEmail(@RequestParam String userName,@RequestParam String email);
}
